<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>招投标管理</title>
<link href="/css/formcheck.css" rel="stylesheet" >
<link rel="import" href="/includes/baseInclude.html">
<style type="text/css">
.ui-jqgrid tr.jqgrow td { white-space: normal !important; height:auto; }
</style>
</head>
<body ng-app="biddingApp" ng-controller="biddingCtrl">
	<div id="manage-area-title">
	<nav class="breadcrumb">
		<div style="margin-top: -7px;">
		<i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span>
		销售管理 <span class="c-gray en">&gt;</span> 招投标管理 <a
			class="btn btn-success radius r mr-20"
			style="line-height: 1.6em; margin-top: 3px"
			ng-click="reload()" title="刷新"><i
			class="Hui-iconfont">&#xe68f;</i></a>
			</div>
	</nav>
	<div class="pd-20"  >
	    <div class="text-c" style="margin-bottom:10px">
			<form class="Huiform" target="_self">
				<input ng-model="projectName" type="text" class="input-text" style="width:250px" placeholder="招投标名称" id="" name="">
				<button ng-click="search(projectName)"  class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜索招投标</button>
			</form>
	    </div>
		<div class="cl pd-5 bg-5 ">
			<span class="l"> 
			<a href="javascript:;" ng-click="datadel()" juge-permission="biddingDelete"
			   class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除
			</a> 
			<a class="btn btn-primary radius " juge-permission="biddingAdd" ng-click="layer_show('添加招投标','biddingManagement-add.html?flagId=','800px','550px')" >
			<i class="Hui-iconfont">&#xe600;</i> 添加招投标
			</a>
			<a class="btn btn-success radius" juge-permission="biddingSearch" ng-click="layer_show('高级搜索','binningManagement-search.html?','800px','460px')">
			<i class="Hui-iconfont">&#xe665;</i> 高级搜索
			</a>
			</span> 
		</div>
    
		<div style="clear: both;"></div>
		<div  style="width: 100%;" class="jqGrid_wrapper">
			<table id="biddingTableList"></table>
			<div id="biddingTableListPager"></div>
		</div>
	</div>	
	</div>
    <script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
	<script type="text/javascript" src="/pc/base/js/laydate/laydate.js"></script>
    <script type="text/javascript" src="/js/base/jqGrid.js"></script> 
    <script type="text/javascript" src="/js/libs/gridUtil.js"></script>
	<script type="text/javascript" src="/js/instruct.js"></script>
	<script>
		var app = angular.module('biddingApp',['permissionApp']);
		    app.controller('biddingCtrl',function($scope,$http){
				/*刷新*/
				$scope.reload = function(){
					$scope.projectName = "";
					$scope.search();
				}
				/*搜索合同*/
				$scope.projectName = "";
				$scope.search = function(name){
					var data = {'SalesBidding.name':name};
					$("#biddingTableList").setGridParam({
						url:"/salesBidding/findBidding",
						datatype: "json",
						page:1
					});
					$("#biddingTableList").setPostData(data);
					$("#biddingTableList").trigger("reloadGrid");
				};

		    	//弹出框layerShow
		    	$scope.layer_show = function(title,url,width,height){
                   layer.open({
	                   	type:2,
	                   	title:title,
	                   	content:url,
	                   	shadeClose:false,
	                    shade:0.2,
	                    maxmin: true,
	                    closeBtn:1,
	                    area: [width, height],
	                    end:function(){
	                    	refresh();//关闭layer,刷新方法
	                    }
                   })
		    	};

				/*选中删除 checkBox*/
				function getSelectedIds(){
					$scope.selectedIds = $("#biddingTableList").jqGrid("getGridParam", "selarrrow");
					return $scope.selectedIds;
				};
				/*批量删除*/
				$scope.datadel = function() {
					getSelectedIds();
					if($scope.selectedIds.length==0){//没有选择一个的时候提示
						layer.msg('请至少选中一条数据再操作！',{icon:2,time:1000});
						return;
					}else{
						layer.confirm('确定要删除么，操作需谨慎？',function(){
							var dataManyDele={
								'biddingIds':$scope.selectedIds
							};
							$http.post('/salesBidding/deleteBiddingBatch',dataManyDele,postCfg)
									.success(function(resp){
										if(validateSuccessData(resp)){
											layer.msg('删除成功',{icon:1,time:500});
											window.refresh();
										}else{
											layer.msg(resp.errorMessage,{icon:2,time:1000});
										}
									});
						});
					};
				};

		    });
	</script>
	<script>
		$(document).ready(function(){
			$("#biddingTableList").jqGridFunction({
				url:'/salesBidding/findBidding',
				dataType:'json',
				postData:{},
				styleUI:'Bootstrap',
				autowidth:true,
				viewrecords:true,
				shrinkToFit:true,
				rowList:[10,20,50,100],
				colNames:['主键','操作','招投标名称','招投标编号','招标人','代理公司','所属行业','招标金额(￥)'],
				colModel:[{name:'id',key:true,hidden:true},
				          {name:'operat',width:60,formatter:operatFormatter},
				          {name:'name',sortable:true,formatter:infoFormatter},
				          {name:'number',sortable:true},
				          {name:'biddingPerson',sortable:true},
				          {name:'agencyCompany',sortable:true},
					      {name:'industry.itemName',sortable:true},
				          {name:'biddingAmount',sortable:true,formatter:totalFormatter}
					     ],
				height:$(document).height()-$("#manage-area-title").height()-130,
				rownumbers: true, // 显示行号
				multiselect:true

			});
			 $(window).bind('resize', function () {  
		            var width = $('.jqGrid_wrapper').width();  
		            $("#biddingTableList").setGridWidth(width); 
		           // $("#biddingTableList").setGridWidth($(window).width()*0.99);　
		        });
			function operatFormatter(cellvalue, options, rowObject){
				var operateHtml = "";
				if(isPermission("biddingUpdate")){
				    operateHtml +='<a title="编辑" href="javascript:layer_shows('+rowObject.id+',1)" class="ml-5" style="text-decoration: none"><i class="Hui-iconfont">&#xe6df;</i></a>';
				}
				if(isPermission("biddingDelete")){
				    operateHtml +='<a title="删除" href="javascript:deleBid('+rowObject.id+')"  class="ml-5" style="text-decoration: none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
				}
				return operateHtml;
			};
			//总金额单位
			function totalFormatter(cellvalue, options, rowObject){
				//var operateHtml = "";
				if(rowObject.total != null && rowObject.total != ""){
					return rowObject.total+"￥";
				}else{
					return "";
				}
			};
			//详情页
			function infoFormatter(cellvalue, options, rowObject){
				var infoHtml = "";
				var name = rowObject.name;
				infoHtml +='<a href="javascript:layer_shows('+rowObject.id+',2)" class="ml-5" style="color:#1E90FF;text-decoration: none">'+name+'</a>';
				return infoHtml;
			};
			
			
		});

		//弹出层
		function layer_shows(id,flag){
			if(flag == 1){
				var title = "编辑招投标表";
				var url = 'biddingManagement-add.html?editId='+id+'&flagId='+'edit';
				var w = "800px";
				var h = "550px";
			}else{
				var title = "招投标表详情";
				var url = 'biddingManagement-detail.html?editId='+id+'&flagId='+'edit';
				var w = "800px";
				var h = "550px";
			}
			layer.open({
				type: 2,
				area: [w , h],
				fix: false, //不固定
				maxmin: true,
				shade:0.2,
				title: title,
				content: url,
				end:function(){
					refresh();
				}
			});
		}

		/*删除*/
		function deleBid(id){
			layer.confirm('确定要删除吗？操作需谨慎',function(){
				$.ajax({
					type:'post',
					dataType:'json',
					async:true,
					url:'/salesBidding/deleteBidding',
					data:{
						'id':id
					},
					success:function(data){
						if(data.errorMessage == null){
							layer.msg('已删除!',{icon:1,time:500});
							refresh();
						}else{
							layer.msg(data.errorMessage,{icon:2,time:1000})
						}
					}
				});
			});
		}

		//高级搜索
		function biddingSearch(data){
			$("#biddingTableList").setGridParam({
				url:"/salesBidding/findBidding",
				datatype: "json",
				page:1
			});
			$("#biddingTableList").setPostData(data);
			$("#biddingTableList").trigger("reloadGrid");
		}
		//刷新
		function refresh(){
			$("#biddingTableList").trigger("reloadGrid");
		};


	</script>
</body>
</html>